package OtherMethod;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class PicModifier {
	
	public static final String DELAMA = "_";
	
	public void ACT001_doFileNameModify(String dirPathOrigin, String dirPathTarget) {
		//read all file information of original path
		File pathOrigin = new File(dirPathOrigin);
		String[] listFileName = pathOrigin.list();
		//start to modify file name and store to target file path
		int index = 0;
		String curFileName = null;
		String[] curTokenList = null;
		File pathTarget = new File(dirPathTarget);
		String newFileName = null;
		if(!pathTarget.exists()) {
			pathTarget.mkdir();
		}
		while(index < listFileName.length) {
			curFileName = listFileName[index];
			curTokenList = curFileName.split(PicModifier.DELAMA);
			newFileName = curTokenList[0] + PicModifier.DELAMA + curTokenList[1] + ".jpg";
			//start to copy file
			try {
				InputStream in = new FileInputStream(dirPathOrigin + "/" + curFileName);
				OutputStream out = new FileOutputStream(dirPathTarget + "/" + newFileName);
				byte[] buf = new byte[1024];
			    int len;
			    while ((len = in.read(buf)) > 0) {
			        out.write(buf, 0, len);
			    }
			    in.close();
			    out.close();
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			index = index + 1;
		}
	}
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		new PicModifier().ACT001_doFileNameModify(args[0], args[1]);
	}
}
